<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        .box1 {
            height: 100px;
            width: 100px;
        }

        .box2 {
            height: 100%;
            width: 100%;
            background-color: #000;

        }
    </style>
</head>

<body>
    <div id="app">
        <div class="box1">
            <div class="box2" v-show="show"></div>
        </div>
        <button @click="btnClick">{{show}}</button>
        <h1>v-bind</h1>
        <!-- 使用v-bind绑定style时需要使用对象,而且需要给非变量添加'',标记为字符串 -->
        <div class="box1" :title="color.red" :style="{backgroundColor:color}">
            <!-- 在react中没法将对象直接写入函数中,在vue中可以直接将其写入插值运算符中 -->
        </div>
        <div> {{color}} </div>
        <div>{{[45,45,45]}}</div>
        <button @click="colorChange">点击切换颜色</button>
    </div>
    <script>
        Vue.config.productionTip = false;
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    show: true,
                    color: 'rgb(100,100,100)'
                };
            },
            methods: {
                btnClick: function () {
                    this.show = !this.show
                },
                colorChange: function (e) {
                    let arr = new Array(3)
                    // console.log(arr.length);// 但是会有length
                    // 空数组不会被遍历
                    arr.fill('')
                    //使用forEach不会修改原数组
                    let newArr = arr.map(item => {
                        item = Math.round(Math.random() * 255)
                        return item
                    })
                    let str = `rgb(${newArr.join(',')})`
                    this.color = str

                }
            },
        });
    </script>
</body>

</html>